<?php
class Application_Model_DbTable_StoreItem extends Application_Model_DbTable_DomainObject{
	
	protected $_name = 'uuch_storeitem';
	
	public function getMapper(){
		return array('id','storeId','dateInStore','dateOut','operatedate','productName',
                    'orderNo','price','quantity','productId','intype','state','operate','Logistics','logisticsName'
            ,'userid','image','weight','remark','createdate','wayId','isPack','bignessType'
            ,'length','width','height','volumeWeight','canVacuum',"isProblem","remarkName"
            ,'vacuumWeight','noPackageWeight','isEmbargo','itemType','barcode','isSelected','cnShipFee','isdelete','embargoReason','locationNo','operateName','interior','dateOver');
	}

    /*
    * 根据用户序号获取当前库存信息
    */
    public  function getByUser($userId,$state,$start,$row){

        $db = $this->getAdapter();
        $filter = $db->quoteInto(' userId = ?', $userId);            
        $filter = $db->quoteInto(' state = ?', $state);   
        $rows = $this->fetchAll($filter,'id',$row,$start);

        $result = array();
        foreach ($rows as $row){
            array_push($result,$this->convertRowToObject($row));

        }           
        return $result;
    }   

    public  function getByIds($ids)
    {
        $Aids = explode(",", $ids);            
        $db = $this->getAdapter();        
        $filter = $db->quoteInto(' id IN(?) ', $Aids);   
        $rows = $this->fetchAll($filter,'id');            
        $result = array();
        foreach ($rows as $row)
                array_push($result,$this->convertRowToObject($row));
        return $result;
    }

    /*
        * 根据运单序号获取仓库列表信息
        */
    public function  getByWayid($wayid){
        $db = $this->getAdapter();
        $sql="SELECT * FROM `uuch_storeitem` where wayid=".$wayid." order by locationNo";
        $result = $db->query($sql);

        if (count($result) > 0) {
            $items = array();

            foreach ($result as $row) {
                array_push($items,$this->convertArrayToObject($row));
            }        
            return $items;
        }            
        else{
            return null;
        }

    }



    /*
        * 根据用户名，状态获取当前仓库记录总数
        * @param int $userid 用户序号
        * @param int $state 用户序号
    * @return int
        */
    public  function getItemCount($user,$state){

        $db = $this->getAdapter();
        if( $state ==-1){ 
            $result = $db->query('select count(*) from uuch_storeitem where userid='.$user);

        }
        else{
            $result = $db->query('select count(*) from uuch_storeitem where userid='.$user.' and state='.$state );
        }         

        $c = $result->fetchColumn();

        return $c;;
    }

    public  function getInTypeCount($user,$state){

        $db = $this->getAdapter();
        if( $state ==-1){ 
            $result = $db->query('select intype, count(*) as C from uuch_storeitem where userid='.$user.' Group by intype');

        }
        else{
            $result = $db->query('select intype,count(*) as C from uuch_storeitem where userid='.$user.' and state='.$state .' Group by intype');
        }   
        $c = $result->fetchAll();
        return $c;;
    }
    
    public function getActCnShipFee($logistics){
        $sql = "select sum(cnShipFee) from uuch_storeitem where logistics = '".$logistics."' and isdelete != 1";
        $db = $this->getAdapter();
        $result = $db->query($sql);
        return $result->fetchColumn();
    }

        
}